package awesome;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

/**
 * Handles logging.
 * 
 * @author Chris Carpenter
 * 
 */
public class ServerLogger {
	
	/**
	 * Initializes the server logs.
	 * 
	 * Server.log provides information and error log about
	 * server events.
	 * 
	 * Access.log provides a list of incoming requests.
	 */
	public static void initializeLogger() {
		Handler errorHandler, accessHandler;
		try {
			//initialize file handlers
			errorHandler = new FileHandler("server.log");
			accessHandler = new FileHandler("access.log");
			
			//set formats
			SimpleFormatter formatter = new SimpleFormatter();
			errorHandler.setFormatter(formatter);
			errorHandler.setFormatter(formatter);
			
			//get loggers
			Logger serverLogger = Logger.getLogger("awesome.server");
			Logger accessLogger = Logger.getLogger("awesome.access");
			
			//add handlers
			serverLogger.addHandler(errorHandler);
			accessLogger.addHandler(accessHandler);
			
			//set level
			serverLogger.setLevel(Level.WARNING);
			accessLogger.setLevel(Level.ALL);
			//TODO set log level from config
			
		} catch (SecurityException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
